import game from "./game";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ufoCtrl extends cc.Component {

    //isDie=false;
    speed
    isGet
    

    reIsGet:Function;


    // window.Global = {
    //     backNode: null,
    //     backLabel: null,
    // };

     onLoad () {
        this.init();
     }

    start () {
       
    }

    init() {
        this.isGet = false;
         let anim = this.getComponent(cc.Animation)
         anim.play("ufo_normal");
        this.speed = 200 + Math.random() * 200;
    }

    hit() {
        let gg = cc.find("Canvas");
        let sc = gg.getComponent(game);
        //sc.playSoundEnemyDie();
        this.isGet = true;
       // this.reIsGet();
        let anim = this.getComponent(cc.Animation)
        anim.play("ufo_boom");
        sc.playUfoSound();
        //console.log("hit" + this.isDie);


    }

    reGet(){
        return this.isGet;
    }

    bian(){
        this.isGet=true;
    }

    boomOver1() {
        this.isGet = true;
        let gg = cc.find("Canvas");
        let sc = gg.getComponent(game);
        sc.onUfoKilled(this.node);
        //console.log("ufo +1 ");
        //sc.addScore(100/2);
    }

    // onCollisionEnter(other,self){
    //     if(self.tag == 8){
    //         this.hit();
    //         this.isGet=true;
    //         //console.log(this.isGet+" "+"ufoCtrl");
            
    //     }
        
    // }

     update (dt) {
        
        let gg = cc.find("Canvas");
        let sc = gg.getComponent(game);
        if (this.isGet == false) {
            if (sc.gameType == 1 || sc.gameType == 3) {
                this.node.y -= this.speed * dt;
            }
        }

        if (this.node.y < -(cc.winSize.height / 2 + this.node.height / 2)) {
            sc.onUfoKilled(this.node);
            console.log("uof,kill");

        }
     }
}
